/**
 * 
 */
package org.fire.client;

import io.netty.channel.ChannelHandlerContext;

import java.util.Arrays;

import org.fire.client.TestPb.TestMsg;

/**
 * @author lhl
 *
 */
public class TestLogic
{
	public static void testSend(ChannelHandlerContext ctx)
	{
		Packet packet = new Packet();
		TestMsg.Builder builder = TestMsg.newBuilder();
		builder.setId(10086);
		builder.setName("client send to server: cmcc");
		builder.setAge(10);
		packet.setBody(builder.build().toByteArray());
		ctx.writeAndFlush(packet);
	}

	public static void testRecv(Object msg)
	{
		Packet packet = (Packet) msg;
		System.out.println("+++++++++++++++++++++++");
		System.out.println("length: " + packet.getLength());
		System.out.println("body: " + Arrays.toString(packet.getBody()));
		if (packet.getBody() != null)
		{
			TestMsg testMsg = Packet.parse(packet, TestMsg.getDefaultInstance());
			System.out.println(testMsg.getId() + ", " + testMsg.getName() + ", " + testMsg.getAge());
		}
		System.out.println("+++++++++++++++++++++++");
	}
}
